<template>
    <div class="layerPublicStyle">
        <lay-form-item label="终端类型" >
            <lay-checkbox name="like" :value="true" @change="checkboxChange"  v-model="formData.userType">
                {{ toggleOptions.terminal_type[formData.terminal_type] }}
        </lay-checkbox>
        </lay-form-item>
        <lay-form-item label="发起用户" class="_row_style">
            <div class="_content">
                {{  formData.userInfo.text }}
            </div>
        </lay-form-item>
        <lay-form-item label="提现金额" class="_row_style">
            <div class="_content">
                {{  formData.withdraw_amount_yuan }} 元
            </div>
        </lay-form-item>
        <lay-form-item label="提现附言" class="_row_style">
            <lay-textarea placeholder="用户未输入任何提现附言" style="width: 350px;" :resize="true" :disabled="true" v-model="formData.withdraw_remark"></lay-textarea>
        </lay-form-item>
        <lay-form-item label="审核备注" class="_row_style">
            <lay-textarea placeholder="请输入审核备注" style="width: 350px;" :resize="true"  re v-model="formData.operator_remark"></lay-textarea>
        </lay-form-item>

        <lay-form-item label="提现状态" class="_row_style">
            <lay-radio v-model="formData.withdraw_status" name="action" :value="0" label="出款成功"></lay-radio>
            <lay-radio v-model="formData.withdraw_status" name="action" :value="1" label="正在审核"></lay-radio>
            <lay-radio v-model="formData.withdraw_status" name="action" :value="2" label="提款拒绝"></lay-radio>
            <lay-radio v-model="formData.withdraw_status" name="action" :value="3" label="正在出款"></lay-radio>
            <lay-radio v-model="formData.withdraw_status" name="action" :value="4" label="出款失败"></lay-radio>
        </lay-form-item>

    </div>
</template>

<script setup>
import { reactive,nextTick,onMounted,ref} from 'vue'
import BigJs from 'big.js'
const db = uniCloud.database()

const props = defineProps({
    serverData:Object,
    callback:Function
})

const { user_id:[userInfo],withdraw_amount,withdraw_remark,operator_remark,withdraw_status,terminal_type,_id:dataId } =props.serverData;
const withdraw_amount_yuan= +BigJs(withdraw_amount).div(100)

const toggleOptions=reactive({
    terminal_type:{
        0:`商户`,
        1:`骑手`
    },
    withdraw_status:{
        0:`出款成功`,
        1:`正在审核`,
        2:`提款拒绝`,
        3:`正在出款`,
        4:`出款失败`
    }
})
const formData=reactive({
        userType:true,
        userInfo,
        withdraw_amount_yuan,
        withdraw_remark,
        operator_remark,
        withdraw_status,
        terminal_type
    })
    onMounted(async () => {
        props.callback([
            parentCallVerify,
        ]);
    })

    async function checkboxChange(){
        await nextTick()
        formData.userType=true
    }

    function parentCallVerify(){
        return new Promise(async resolve=>{
            const results= await new Promise((next)=>{
                const confirmText=`修改提现状态如下：${toggleOptions.withdraw_status[withdraw_status]} => ${toggleOptions.withdraw_status[formData.withdraw_status]}`
                layer.confirm(confirmText, {
                    title:`操作提示`,
                    area:[`400px`,`170px`],
                    icon:3,
                    btn: [{
                        text:`确定`,
                        callback:async (layerId)=>{
                            next(1);
                            layer.close(layerId);
                        }
                    },{
                        text:`取消`,
                        callback:(layerId)=>{
                            next(0)
                            layer.close(layerId);
                        }
                    }]
                }) 
            }) 
            if(results===1){
                uni.showLoading({
                    title: `正在处理`,
                    mask:true
                });
                try {
                    await db.collection(`food-withdraw-list`)
                    .where({
                        _id:dataId
                    })
                    .update({
                        operator_remark:formData.operator_remark,
                        withdraw_status:formData.withdraw_status
                    })
                    uni.hideLoading()
                    layer.msg(`处理成功`, { time: 1500,icon:1 })
                    resolve(1)
                } catch (error) {
                    console.error(error)
                    uni.hideLoading()
                    return layer.msg(error.errMsg, { icon : 2, time: 1500})
                }

            }
        })
    }

</script>

<style lang="stylus" scoped>

</style>


